<template>
  <view>
    <!-- 显示购物车无商品空页面 -->
    <view class="empty" v-if="cart.length === 0">
      <image src="../../static/tab_icons/empty.png"></image>
    </view>
    <!-- 显示购物车有商品页面 -->
    <view class="cart-container" v-else>
      <!-- 收货地址 -->
      <my-adress></my-adress>
      <!-- 购物车商品列表的标题区域 -->
      <view class="cart-title">
        <!-- 左侧的图标 -->
        <uni-icons type="shop" size="18"></uni-icons>
        <!-- 描述文本 -->
        <text class="cart-title-text">购物车</text>
      </view>
      <!-- 购物车商品列表展示 -->
      <view class="list">
        <!-- 滑动删除 -->
        <uni-swipe-action>
          <block v-if="cart.length > 0" v-for="(it,i) in cart" :key="i" >
          <!-- :right-options="options"关系到滑动 -->
            <uni-swipe-action-item :right-options="options" @click="swipeActionClickHandler(it.goods_id)">
              <my-good :goods.sync="it" :show-radio="true" :show-num="true"></my-good>
            </uni-swipe-action-item>
          </block>
        </uni-swipe-action>
      </view>
      <!-- 结算区域 -->
      <my-gopay></my-gopay>
    </view>
  </view>
</template>

<script>
  import {mapState,mapMutations} from 'vuex'
  export default {
    data() {
      return {
        options: [{
              text: '删除', // 显示的文本内容
              style: {
                backgroundColor: '#C00000' // 按钮的背景颜色
              }
            }]
      };
    },
    computed:{
      ...mapState('cart',['cart'])
    },
    methods:{
      ...mapMutations('cart',['REMOVEGOOD']),
      // 点击了滑动操作按钮
      swipeActionClickHandler(id) {
        // 删除商品
        this.REMOVEGOOD(id)
      }
    }
  }
</script>

<style lang="scss">
  .empty {
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: #fff;
    image {
      width: 175px;
      height: 175px;
    }
  }
  .cart-container {
    padding-bottom: 50px;
  }
.cart-title {
  height: 40px;
  display: flex;
  align-items: center;
  font-size: 14px;
  padding-left: 5px;
  border-bottom: 1px solid #efefef;
  .cart-title-text {
    margin-left: 10px;
  }
}
</style>
